package com.fhs.tools.config;

import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
import com.fhs.tools.mp.XMLRefresher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * xml 刷新器配置
 * by wanglei
 */
@Configuration
@AutoConfigureAfter(MybatisPlusAutoConfiguration.class)
public class MPXMLRefresherConfig {

    private static Logger LOG =  LoggerFactory.getLogger(MPXMLRefresherConfig.class);

    @Bean
    @ConditionalOnProperty(name = "fhs.tools.mp-xml-refresh.enable", havingValue = "true")
    public XMLRefresher getXMLMapperLoader(MybatisPlusProperties plusProperties){
        XMLRefresher loader = new XMLRefresher();
        loader.setMapperLocations(plusProperties.resolveMapperLocations());
        LOG.info("fhs tools xml refresh init:" + plusProperties.getMapperLocations() + "--" + loader.getMapperLocations());
        return loader;
    }


}
